package com.apache.email;

import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;

//apache common email send,
public class EmailSend {
	public static void main(String[] args) throws EmailException {
		try
	    {
	        EmailAttachment attachment = new EmailAttachment();   /*new一个附件*/
	        attachment.setPath("d:\\1.docx");   /*附件的地址*/
	        attachment.setDisposition(EmailAttachment.ATTACHMENT);  
	        attachment.setDescription("附件文档");   /*附件的描述*/
	        attachment.setName("1.docx");    /*附件的名称，必须和文件名一致*/
	            
	        HtmlEmail email = new HtmlEmail();   /*new一个HtmlEmail*/
	        email.setAuthentication("webmaster@lvmama.com","lvmama&admin");     /*username和password是邮箱的用户名和密码*/
	        email.setHostName("mail.lvmama.com");   /*发送邮件服务器的IP或域名*/
	        email.setFrom("lijiepeng.tuobi@gmail.com");    /*发件人邮箱*/
	        email.addTo("lijiepeng@lvmama.com");    /*收件人邮箱，可以写多个*/
	        email.addTo("lijiepeng1984@gmail.com");
	        email.setCharset("GB2312");    /*设置编码，必须有这条语句，否则会有乱码*/
	        email.setSubject("试试中文");    /*邮件标题*/
	        email.setHtmlMsg("<html>这是封测试邮件</html>"); /*邮件内容*/
	        email.attach(attachment);    /*将附件绑定在邮件中*/
	        email.send();    /*发出邮件！*/
	    }
	    catch(Exception e)
	    {
	        e.printStackTrace();
	    }
	}
}
